<template>
	<view>
		<u-search :focus="true" @custom="custom" @search="custom" placeholder="账号/手机号" :animation=true v-model="keyword" :color="color" searchIconColor="#909399" :actionStyle="actionStyle"></u-search>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
import { api } from '../../api/api';
import { myRequest } from '../../util/api';
	export default {
		data() {
			return {
				keyword: '',
				color: 'black',
				actionStyle: {
					color: '#3e76a1'
				},
			};
		},
		methods: {
			// 点击搜索按钮事件
			async custom() {
				uni.showLoading({
					title: '正在查找联系人...',
					mask: true
				});
				// 请求搜索好友接口
				await myRequest({
					url: api.searchFriend,
					method: 'POST',
					data: {
						searchKey: this.keyword,
					},
					success: (res) => {
						if (res.data.code == 200 && res.data.httpCode == 200){
							const result = res.data.data;
							this.$u.route('pages/searchResult/searchResult', {
								id: result.id,
								miniAvatar: result.miniAvatar,
								nickname: result.nickname,
								area: result.area,
								signature: result.signature,
								isFriend: result.isFriend,
								sex: result.sex,
							});
						}
						uni.hideLoading();
					}
				});
			},
		}
	}
</script>

<style lang="scss">

</style>
